﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/Basic.Master" AutoEventWireup="true" CodeBehind="ExportTableColumns.aspx.cs" Inherits="PMS.UI.BD.ExportTableColumns" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script>
        $(function () {
            var height = $("#divTotal").height();

            var content = parseFloat(height) - 30;
            $("#tbList").css("height", content);
        });
    </script>
    <script>
        var TotalId = com.get.TotalId;
        $(function () {
            $("#tbList").datagrid({
                url: '/Logic/BD/ExportTableAjax.aspx?method=GetTableColumnByTotalId',
                loadMsg: '数据加载中请稍后……',
                queryParams: { TotalId: TotalId },
                rownumbers: true,
                idField: "Id",
                singleSelect: true,

                striped: true,
                frozenColumns: [[{ field: 'ck', checkbox: true, width: 30 },
                {
                    field: 'Columns', title: '列名', align: "center", width: 120, editor: {
                        type: "validatebox",
                        options: {
                        }
                    }
                },
                 {
                     field: 'Name', title: '中文名称', width: 120, align: "center", editor: {
                         type: "validatebox",
                         options: {
                         }
                     }
                 }, {
                     field: 'IsExport', title: '是否导出', align: "center", width: 120, formatter: function (value, row, index) {
                         return com.getArrayText(StaticCombo.IsExport, value);
                     }, editor: {
                         type: "combobox",
                         options: {
                             data: StaticCombo.IsExport,
                             valueField: 'value',
                             textField: 'text',
                             required: true
                         }
                     }
                 }, {
                     field: 'Orders', title: '排序', width: 120, align: "center", editor: {
                         type: "validatebox",
                         options: {
                         }
                     }
                 },
                 {
                     field: 'Type', title: '类型', align: "center", width: 120, formatter: function (value, row, index) {
                         return com.getArrayText(StaticCombo.IsExportType, value);
                     }, editor: {
                         type: "combobox",
                         //value: "1",
                         options: {
                             data: StaticCombo.IsExportType,
                             
                             valueField: 'value',
                             textField: 'text',
                             required: true
                         }
                     }
                 }, {
                     field: 'Note', title: '备注', width: 120, align: "center", editor: {
                         type: "validatebox",
                         options: {
                         }
                     }
                 }

                ]], onAfterEdit: function (rowIndex, rowData, changes) {
                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/BD/ExportTableAjax.aspx?method=EditExportColumn",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    } else if (editAction == "add") {
                        com.ajax({
                            url: "/Logic/BD/ExportTableAjax.aspx?method=AddExportColumn",
                            data: $.extend(rowData, { TotalId: TotalId }),
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    }
                    editRow = undefined;
                }, onCancelEdit: function (rowIndex, rowData) {
                    $("#tbList").datagrid("rejectChanges");

                }
            });
        });

    </script>

    <script>
        editRow = undefined;
        editAction = undefined;
        function funcSearch() {
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);

        }
        function funcAdd() {
            //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
            if (editRow != undefined) {

            }
            //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
            if (editRow == undefined) {
                $("#tbList").datagrid("insertRow", {
                    index: 0, // index start with 0
                    row: {

                    }
                });
                //将新插入的那一行开户编辑状态
                $("#tbList").datagrid("beginEdit", 0);
                //给当前编辑的行赋值
                editRow = 0;
                editAction = "add";
            }
        }
        function funcEdit() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    //   var index = row.Id;
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }
        function funcRemove() {
            $.messager.confirm('确认对话框', '您确定删除该记录吗？', function (r) {
                if (r) {
                    var rowData = $("#tbList").datagrid("getSelected");
                    if (rowData) {
                        com.ajax({
                            url: '/Logic/BD/ExportTableAjax.aspx?method=DelExportColumn',
                            data: { Id: rowData.Id },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })

                            }

                        });
                    }
                }
            });
        }

        function funcSave() {
            $('#tbList').datagrid('endEdit', editRow);
        }
        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }
        function funcReload() {
            $("#form1").form("reset");
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
        }
        function sayHello() {
            alert("a");
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div id="divTotal" style="height: 100%; width: 100%">
        <table id="tbList" title="导出Excel表格列 " style="width: 100%; height: 300px">
        </table>
    </div>
    <div>
        <img src="../../Images/icon-download.jpg" onclick="sayHello()" id="imgDownload"  />

    </div>
</asp:Content>
